/*
 * @Author: GISER_GUI
 * @Date: 2025-02-15 20:52:05
 * @LastEditors: GISER_GUI
 * @LastEditTime: 2025-03-16 15:27:14
 * @Description: 卡牌接口
 */

import axios from 'axios'
import type { AxiosRequestConfig, AxiosResponse } from 'axios'

const apiHttp = '/mh'
// 获取卡牌列表
const prizesList: string = apiHttp + '/cards/getPrizesList'

const cardList: string = apiHttp + '/cards/getCardList'

// 奖牌等级
const prizesLevels: string = apiHttp + '/cards/getLevels'

const addPrizesLevel: string = apiHttp + '/cards/addLevels'

const addPrizes: string = apiHttp + '/cards/addPrizes'

const delPrizesLevel: string = apiHttp + '/cards/delLevels'

const delPrizes: string = apiHttp + '/cards/delPrizes'

const updatePrizesLevel: string = apiHttp + '/cards/updataLevels'

const updataPrizes: string = apiHttp + '/cards/updataPrizes'

const updataState: string = apiHttp + '/cards/updataState'

const randomPrizes: string = apiHttp + '/cards/randomPrizesList'

// 重置
const resetPrizesState: string = apiHttp + '/cards/resetPrizesState'

const changePrizesIndex: string = apiHttp + '/cards/changePrizesIndex'

// 当axios返回401或403时，会调用该方法，跳转到登陆页面
axios.interceptors.response.use(
  (response: AxiosResponse) => {
    return response
  },
  (error) => {
    if (error.response.status === 401 || error.response.status === 403) {
      window.location.href = '/login'
    }
    return Promise.reject(error)
  },
)

function getPrizesLevelsListHttp(token: string) {
  const config: AxiosRequestConfig = {
    headers: {
      Authorization: `${token}`,
    },
  }
  return axios.get(prizesLevels, config)
}

function addPrizesLevelHttp(token: string, params: any) {
  const config: AxiosRequestConfig = {
    headers: {
      Authorization: `${token}`,
    },
  }
  return axios.post(addPrizesLevel, params, config)
}

function addPrizesHttp(token: string, params: any) {
  const config: AxiosRequestConfig = {
    headers: {
      Authorization: `${token}`,
    },
  }
  return axios.post(addPrizes, params, config)
}

function delPrizesLevelHttp(token: string, params: any) {
  const config: AxiosRequestConfig = {
    headers: {
      Authorization: `${token}`,
    },
  }
  return axios.post(delPrizesLevel, params, config)
}

function delPrizeslHttp(token: string, params: any) {
  const config: AxiosRequestConfig = {
    headers: {
      Authorization: `${token}`,
    },
  }
  return axios.post(delPrizes, params, config)
}

function updatePrizesHttp(token: string, params: any) {
  const config: AxiosRequestConfig = {
    headers: {
      Authorization: `${token}`,
    },
  }
  return axios.post(updataPrizes, params, config)
}

function updatePrizesLevelHttp(token: string, params: any) {
  const config: AxiosRequestConfig = {
    headers: {
      Authorization: `${token}`,
    },
  }
  return axios.post(updatePrizesLevel, params, config)
}

//  ---

function getPrizesListHttp(token: string) {
  const config: AxiosRequestConfig = {
    headers: {
      Authorization: `${token}`,
    },
  }
  return axios.get(prizesList, config)
}

function getCardListHttp(token: string) {
  const config: AxiosRequestConfig = {
    headers: {
      Authorization: `${token}`,
    },
  }
  return axios.get(cardList, config)
}

function randomPrizesListHttp(token: string) {
  const config: AxiosRequestConfig = {
    headers: {
      Authorization: `${token}`,
    },
  }
  return axios.post(randomPrizes, {}, config)
}

function updataStateHttp(token: string, params: any) {
  const config: AxiosRequestConfig = {
    headers: {
      Authorization: `${token}`,
    },
  }
  return axios.post(updataState, params, config)
}

function resetPrizesStateHttp(token: string, params: any) {
  const config: AxiosRequestConfig = {
    headers: {
      Authorization: `${token}`,
    },
  }
  return axios.post(resetPrizesState, params, config)
}

function changePrizesIndexHttp(token: string, params: any) {
  const config: AxiosRequestConfig = {
    headers: {
      Authorization: `${token}`,
    },
  }
  return axios.post(changePrizesIndex, params, config)
}

export default {
  getPrizesLevelsListHttp,
  addPrizesLevelHttp,
  delPrizesLevelHttp,
  updatePrizesLevelHttp,
  getPrizesListHttp,
  getCardListHttp,
  delPrizeslHttp,
  addPrizesHttp,
  updatePrizesHttp,
  randomPrizesListHttp,
  updataStateHttp,
  resetPrizesStateHttp,
  changePrizesIndexHttp,
}
